#! /bin/bash

while((1))
do
	echo "用例列表："
	j=0
	for i in $(ls ./scripts/)	#生成用例列表
	do 
		case_list[j]=${i%.*}	 #截取左边${string%chars*} 截取右边 ${string#*chars}											
		echo -e "\e[32m 	$[$j+1] ${i%.*} \e[0m"  #遍历显示用例列表
		((j++))
	done
	echo -e "\e[32m	a 执行所有用例 \e[0m"
	read -p "请选择测试用例：" input
	if [ -z "$input" ]; then	#判断输入是否为空			
		echo -e "\e[31m 输入为空，请重新输入！\e[0m"   
	elif [ "${input}" == a ]; then   #输入a批量执行用例
		echo "执行用例：${input}" 
		for case in ${case_list[*]}; do
			echo "执行用例:${case}"
			datetime=`date +%H%M%S%Y%m%d`
			mkdir -p results/${case}/${datetime}/report
			jmeter.sh -n -t scripts/${case}.jmx -l results/${case}/${datetime}/${case}.jtl -e -o results/${case}/${datetime}/report
		done
		
	elif [ ${case_list[(($input-1))]} ]; then  #输入编号单个执行用例

	
		echo "执行用例：${case_list[(($input-1))]}.jmx"
		datetime=`date +%H%M%S%Y%m%d`
		mkdir -p results/${case_list[(($input-1))]}/${datetime}/report  #创建报告目录
		jmeter.sh -n -t scripts/${case_list[(($input-1))]}.jmx -l results/${case_list[(($input-1))]}/${datetime}/${case_list[(($input-1))]}.jtl -e -o results/${case_list[(($input-1))]}/${datetime}/report
	else
		echo -e "\e[31m 无此选项，请重新输入！\e[0m"
	fi
done

# while((1))
# do
	# read -p "input: " input;
	# case $input in
		# 1)
		# echo $input
		# ;;
		# 2)
		# echo $input
		# ;;
		# *)
		# echo "无此选项，请重新输入！"
		# ;;
	# esac
# done



